#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include "qi_vars.h"
#include "../q_common.h"




/* variables */
struct qi_scopecontainer qi_variables;


/* variables */
int qi_initscopes()
{
	struct qi_scope* tmp;

	if(!(tmp = (struct qi_scope*)malloc(sizeof(struct qi_scope))))
		return Q_STATUS_FATAL;
	memset(tmp->vars, 0, Q_HASH_TABLE_SIZE * sizeof(struct qi_variable));
	tmp->prev = NULL;
	tmp->type = SCOPE_GLOBAL;
	qi_variables.global = qi_variables.current = tmp;
	return Q_STATUS_OK;	
}

int qi_addscope(enum qi_scopetype type)
{
	struct qi_scope* tmp;

	if(!(tmp = (struct qi_scope*)malloc(sizeof(struct qi_scope))))
		return Q_STATUS_FATAL;
	switch(type)
	{
		case SCOPE_NORMAL:
		case SCOPE_FUNC:
			tmp->type = type;
		default:
			free(tmp);
			return Q_STATUS_FATAL;
	}


	memset(tmp->vars, 0, Q_HASH_TABLE_SIZE * sizeof(struct qi_variable));
	tmp->prev = qi_variables.current;
	qi_variables.current = tmp;
	return Q_STATUS_OK;
}

#if 0
static struct qi_variable* qi_variablelookup(const char* const name)
{
	return NULL;
}
#endif

struct qi_variable* qi_variablelookup(const char* const name)
{
	int hash;
	if(!name)
		return NULL;
	hash = q_hashname(name);
	// END IT
	return NULL;
}

int qi_addvariable(const char* const vname, const char* const tname)
{
	return Q_STATUS_OK;
}

/* validation */
int validatevar(const char* const start, const char* const end)
{
	char varname[Q_MAX_SYMBOL_LENGTH];
	int maxlen = end - start + 1;
	if(maxlen > Q_MAX_SYMBOL_LENGTH - 1)
		maxlen = Q_MAX_SYMBOL_LENGTH - 1;
	strncpy(varname, start, maxlen);
	varname[Q_MAX_SYMBOL_LENGTH - 1] = '\0';
	//if(
	return 0;
}







